import asyncio
import time

from app.core.shared import cpu_monitor,vm_monitor,disk_monitor,network_monitor,process_monitor
async def background_monitor():
    """后台监控协程"""
    while True:
        try:

            start_time = time.time()
            await asyncio.gather(
                cpu_monitor.get_cpu_info(),
                vm_monitor.get_memory_info(),
                disk_monitor.get_disk_info(),
                network_monitor.get_network_info(),
            )
            await asyncio.sleep(1)
        except Exception as e:
            print(f"后台监控错误: {e}")
            await asyncio.sleep(10)


async def process_monitor_task():
    """进程监控协程（低频率）"""
    while True:
        try:
            start_time = time.time()
            await process_monitor.update_processes()
            elapsed = time.time() - start_time
            # 设置更长的间隔（如3秒），避免影响其他监控
            await asyncio.sleep(max(3.0 - elapsed, 1))
        except Exception as e:
            print(f"进程监控错误: {e}")
            await asyncio.sleep(10)